<?php include_component('includes','submenu') ?>
<?php $myLib = new myLib(); ?>
<div style="background-color: white;">
<form id="frmSearch" action="<?php echo url_for('@search') ?>" autocomplete="off">
<div class="search_criteria">
    <h1 style="font-weight: normal;">B&uacute;squeda avanzada</h1>
      <br />
    <div class="body">
        <table width="100%">
            <tr>
                <td>Titulo</td>
                <td colspan="3"><input type="text" name="title" size="80" value="<?php echo $sf_user->getAttribute('sparam_title') ?>" /></td>
                <td>Autor</td>
                <td><input type="text" id="author" name="author" value="<?php echo $sf_user->getAttribute('sparam_author') ?>" /></td>
            </tr>
            <tr>
                <td>Rango de Fechas</td>
                <td colspan="3">
                    <input type="text" id="dtp" name="date" value="<?php echo $sf_user->getAttribute('sparam_date') ?>" placeholder="yyyy-mm-dd"/>
                    al
                    <input type="text" id="dtp2" name="date2" value="<?php echo $sf_user->getAttribute('sparam_date2') ?>" placeholder="yyyy-mm-dd"/>
                </td>
                <td>Rating</td>
                <td>
                    <?php
                        for($i=1;$i<=5;$i++){
                            echo image_tag('estrella.png','id="star_'.$i.'" class="star" onclick="star_save('.$i.')" onmouseover="star_on('.$i.')" onmouseout="star_clear()" style="cursor: pointer;"');
                        }
                    ?>
                    <input type="hidden" id="estrellas" name="estrellas" value="<?php echo $sf_user->getAttribute('sparam_star') ?>" />
                </td>
            </tr>
            <tr>
                <td>Categor&iacute;a</td>
                <td>
                  <select style="width: 163px" onchange="loadSubcategories(this.value)" name="category">
                    <option value="">Categoría: </option>
                    <?php foreach($categories as $category){ ?>
                    <option value="<?php echo $category->getId(); ?>" <?php if($sf_user->getAttribute('sparam_category')==$category->getId()){ echo 'selected'; } ?>>
                        <?php echo $category->getDescription() ?></option>
                    <?php } ?>
                  </select>
                </td>
                <td>Subcategoria</td>
                <td>
                  <div id="divAjaxLoadSubcategoriesFrm">
                    <select id="cboSubcategoria" name="subcategory" style="width: 163px;" onchange="selectSubcategory(this.value)">
                        <option value="">Subcategor&iacute;a:</option>
                        <?php foreach($subcategories as $subcategory){ ?>
                        <option value="<?php echo $subcategory->getId() ?>" <?php if($sf_user->getAttribute('sparam_subcategory')==$subcategory->getId()){ echo 'selected'; } ?>>
                            <?php echo $subcategory->getDescription() ?></option>
                        <?php } ?>
                    </select>
                  </div>
                </td>
                <td colspan="2">&nbsp;</td>
            </tr>
            <tr>
                <td colspan="4">&nbsp;</td>
                <td colspan="2">
                  <div style="float: right;">
                    <div class="search_btn" style="width: 75px;">
                      <a href="javascript:$('#frmSearch').submit();">
                        <div style="float: left;padding: 5px;">
                          Buscar
                        </div>
                        <div style="float: left;">
                          <?php echo image_tag('divisor.gif','size=1x15') ?>
                        </div>
                        <div style="float: left;padding: 4px;">
                          <?php echo image_tag('lupa.png','size=16x16') ?>
                        </div>
                      </a>
                    </div>
                    <div class="search_btn">
                    <div style="float: left;padding: 5px;">
                      <a href="<?php echo url_for('@searchClear') ?>">Resetear</a>
                    </div>
                    </div>
                  </div>
                </td>
            </tr>
        </table>
    </div>
</div>
    <?php echo image_tag('triangulo.png','style="margin-left: 60px;"') ?>
</form>
<div class="search_list">
    <div style="margin-left: 30px;color: #0D72BA;">
        <h1 style="font-weight: normal;">Resultados</h1>
    </div>
    <div class="body">
      <?php foreach($articles as $article){ ?>
        <div class="result">
          <table>
            <tr>
              <td>
                <div style="float: left;width: 500px;">
                    <a href="<?php echo url_for('@article?id='.$article->getId().'&slug='.$article->getSlug()) ?>">
                        <b style="text-align: justify;font-size: 12px;"><?php echo $article->getTitle() ?></b></a>
                      <br />
                    <a href="<?php echo url_for('@profile?id='.$article->getOwnerId()) ?>" style="color: #0079CC;">
                      <?php if(count($array_users)>0){ ?>
                        <?php foreach($array_users as $key => $practil_user){ ?>
                          <?php if($practil_user->{'id'} == $article->getAccount()->getPractilAccountId()){ ?>
                            <?php echo $array_users[$key]->{'name'}.' '.$array_users[$key]->{'lastName'}; ?>
                          <?php } ?>
                        <?php } ?>
                      <?php }else{ ?>
                        <?php echo 'Autor Nombre Completo' ?>
                      <?php } ?></a>
                      <br />
                    <?php if(is_object($article->getCategory())){ ?>
                    <?php echo $article->getCategory()->getDescription() ?>
                    <?php } ?>
                    <?php if(is_object($article->getSubcategory())){ ?>
                     / <?php echo $article->getSubcategory()->getDescription() ?>
                    <?php } ?>
                </div>
                <div style="float: left;width: 250px;">
                    <em>-&nbsp;<?php echo $myLib->formattedDate2($article->getCreatedAt()) ?></em>
                </div>
                <div style="float: left;width: 150px;">
                    <?php for($j=1;$j<=5;$j++){ ?>
                      <?php if($j<=round($article->getScore())){ ?>
                        <?php echo image_tag('estrella_on.png') ?>
                      <?php }else{ ?>
                        <?php echo image_tag('estrella.png') ?>
                      <?php } ?>
                    <?php } ?>
                </div>
                <div style="float: left;width: 50px;">
                    <?php echo image_tag('/uploads/author/'.$article->getOwnerId().'.jpg','size=50x50') ?>
                </div>
              </td>
            </tr>
            <tr>
              <td>
                  <br />
                <p style="text-align: justify;">
                  <?php echo substr($article->getSummary(),0,500) ?> ...
                </p>
                  <br />
                <div style="text-align: right;">
                    <a href="<?php echo url_for('@article?id='.$article->getId().'&slug='.$article->getSlug()) ?>"
                       style="color: #0079CC;">
                           ( Leer )</a>
                </div>
              </td>
            </tr>
          </table>
        </div>
      <?php } ?>
    </div>
</div>
</div>
<script type="text/javascript">
<?php /*if($sf_user->hasAttribute('sparam_star')){ ?>
var master_star = <?php echo $sf_user->getAttribute('sparam_star') ?>;
<?php }else{ ?>
<?php }*/ ?>
$(document).ready(function(){
    <?php if($sf_user->hasAttribute('sparam_star')){ ?>
    star_save(<?php echo $sf_user->getAttribute('sparam_star') ?>);
    <?php } ?>
});
$("#dtp").datepicker({
    dateFormat: 'yy-mm-dd'
});
$("#dtp2").datepicker({
    dateFormat: 'yy-mm-dd'
});
function loadSubcategories(cat_id){
    $.ajax({
        type: "post",
        url: "<?php echo url_for('@ajaxLoadSubcategoriesFrm') ?>",
        data: "category_id="+cat_id,
        success: function(html){
            $("#divAjaxLoadSubcategoriesFrm").html(html);
        }
    });
}
</script>